package com.xrit.sunnyday.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.pojo.Member;
import com.xrit.sunnyday.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService{

    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 统计过去一年的会员总数
     */
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //定义一个list，
        List<Integer> memberCount= new ArrayList<Integer>();
        //循环遍历 12个月 12次
        for (int i=0;i<months.size();i++){
            //拿到每个月的日期格式
            String month = months.get(i);
            //去年的月份截至到今年的本月份的会员数量
            Integer count=memberDao.findMemberCountBeforeDate(month);
            memberCount.add(count);
        }
        return memberCount;
    }
}
